﻿using System;
using Imaginecup.stage;
using Microsoft.Xna.Framework;
using imaginecup.objectManager;
using Imaginecup.gameState.malaria.stage;
using Imaginecup.gameState.malaria.componentInit;
using Imaginecup.gameState.malaria.manager;
using Imaginecup.util;
using Imaginecup.loop;
using Imaginecup.gameState.malaria.component;
using Imaginecup.util.input;
using Imaginecup.iterator;

namespace Imaginecup.gameState.malaria.loop
{
    public class UpdateObjectMan:IUpdateAble
    {
        private ObjectManager m_ObjMan;
        private TouchTrailLayer m_TouchTrailMan;

        private bool m_Selected;

        public UpdateObjectMan( ObjectManager objMan  )
        {
            m_ObjMan = objMan;
            m_TouchTrailMan = TouchTrailLayer.GetTouchTrailLayer();
        }
        public void Release()
        {
            m_ObjMan = null;

        }

        public void SetData(Object data)
        {
            m_Selected = (bool)data;
        }
        
        public void Update(GameTime gameTime)
        {            
            ObjectManUpdate(gameTime);
            m_TouchTrailMan.Update();

            if (m_Selected)
            {
                GMessage message = new GMessage(MessageTypeID.MT_CHECK_INPUT , gameTime);
                m_ObjMan.BroadCastMessage(message);
                // m_ParticleMan.GeneratorParticle();
            }
        }

        private void ObjectManUpdate(GameTime gameTime  )
        {
            ObjectUpdate(gameTime, m_ObjMan);

        }


        private void ObjectUpdate(GameTime gameTime , ObjectManager objMan)
        {
            ListIterator list = new ListIterator();
            list.Add(ComponentTypeID.CID_MALARIA_ENTITY);
            list.Add(ComponentTypeID.CID_CHILDREN_ENTITY);
            list.Add(ComponentTypeID.CID_FIELD_ITEM_ENTITY);
            list.Add(ComponentTypeID.CID_FIELD_FROG_ENTITY);
            list.Add(ComponentTypeID.CID_ITEM_ENTITY);
            list.Add(ComponentTypeID.CID_OBSERVER_CHAR);
            list.Add(ComponentTypeID.CID_MESSAGE_NONE);

            objMan.Update(list, gameTime);
        }
    }
}

